package com.lihepeng.leecode.tree.langbuladong;

import com.lihepeng.leecode.tree.TreeNode;

/**
 * 翻转一颗二叉树
 *
 */
public class Solution226 {
    public TreeNode invertTree(TreeNode root) {
        if (root == null) {
            return null;
        }
        revert(root);
        return root;
    }

    /**
     * 翻转操作 将节点的左右节点调换顺序
     *
     */
    private void revert(TreeNode root){
        TreeNode temp = root.left;
        root.left = root.right;
        root.right = temp;
        revert(root.left);
        revert(root.right);
    }
}
